home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 242 / Issue 242 - April 2008 - DPCS0408DVD.ISO / Open Source / AutoHotKey / Source / AutoHotkey104705_source.exe / source / os_version.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2006-09-15  |  5.5 KB  |  206 lines

  1.  
  2. ///////////////////////////////////////////////////////////////////////////////
  3. //
  4. // AutoIt
  5. //
  6. // Copyright (C)1999-2003:
  7. //        - Jonathan Bennett <jon@hiddensoft.com>
  8. //        - Others listed at http://www.autoitscript.com/autoit3/docs/credits.htm
  9. //
  10. // This program is free software; you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation; either version 2 of the License, or
  13. // (at your option) any later version.
  14. //
  15. ///////////////////////////////////////////////////////////////////////////////
  16. //
  17. // os_version.cpp
  18. //
  19. // A standalone class for easy checking of the OS version.
  20. //
  21. ///////////////////////////////////////////////////////////////////////////////
  22.  
  23.  
  24. // Includes
  25. #include "stdafx.h" // pre-compiled headers
  26.  
  27. #ifndef _MSC_VER                                // Includes for non-MS compilers
  28.     #include <windows.h>
  29. #endif
  30.  
  31. #include "os_version.h"
  32.  
  33.  
  34. /*
  35. OSVERSIONINFO structure details
  36. ===============================
  37.  
  38. dwOSVersionInfoSize
  39. Specifies the size, in bytes, of this data structure. Set this member to sizeof(OSVERSIONINFO)
  40. before calling the GetVersionEx function.
  41.  
  42. dwMajorVersion
  43. Identifies the major version number of the operating system as follows. Operating System Value
  44. Windows 95                4
  45. Windows 98                4
  46. Windows Me                4
  47. Windows NT 3.51            3
  48. Windows NT 4.0            4
  49. Windows 2000/XP/2003    5
  50. Windows Vista            6
  51.  
  52. dwMinorVersion
  53. Identifies the minor version number of the operating system as follows. Operating System Value
  54. Windows 95            0
  55. Windows 98            10
  56. Windows Me            90
  57. Windows NT 3.51        51
  58. Windows NT 4.0        0
  59. Windows 2000        0
  60. Windows XP            1
  61. Windows 2003        2
  62. Windows Vista        0 (probably 0 for all Vista variants)
  63.  
  64. dwBuildNumber
  65. Windows NT/2000: Identifies the build number of the operating system.
  66. Windows 95/98: Identifies the build number of the operating system in the low-order word.
  67. The high-order word contains the major and minor version numbers.
  68.  
  69. dwPlatformId
  70. Identifies the operating system platform. This member can be one of the following values. Value Platform
  71. VER_PLATFORM_WIN32s            Win32s on Windows 3.1.
  72. VER_PLATFORM_WIN32_WINDOWS    Windows 95, Windows 98, or Windows Me.
  73. VER_PLATFORM_WIN32_NT        Windows NT 3.51, Windows NT 4.0, Windows 2000, or Whistler.
  74.  
  75. szCSDVersion
  76. Windows NT/2000, Whistler: Contains a null-terminated string, such as "Service Pack 3",
  77. that indicates the latest Service Pack installed on the system. If no Service Pack has
  78. been installed, the string is empty.
  79. Windows 95/98/Me: Contains a null-terminated string that indicates additional version
  80. information. For example, " C" indicates Windows 95 OSR2 and " A" indicates Windows 98 SE.
  81.  
  82. */
  83.  
  84.  
  85. ///////////////////////////////////////////////////////////////////////////////
  86. // Init()
  87. ///////////////////////////////////////////////////////////////////////////////
  88.  
  89. void OS_Version::Init(void)
  90. {
  91.     int        i;
  92.     int        nTemp;
  93.  
  94.     // Get details of the OS we are running on
  95.     m_OSvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  96.     GetVersionEx(&m_OSvi);
  97.  
  98.     // Populate Major and Minor version numbers
  99.     m_dwMajorVersion    = m_OSvi.dwMajorVersion;
  100.     m_dwMinorVersion    = m_OSvi.dwMinorVersion;
  101.     m_dwBuildNumber        = m_OSvi.dwBuildNumber;
  102.  
  103.     // Get CSD information
  104.     nTemp = (int)strlen(m_OSvi.szCSDVersion);
  105.  
  106.     if (nTemp > 0)
  107.     {
  108.         //    strip trailing
  109.         for (i=nTemp-1; i>0; i--)
  110.         {
  111.             if ((char) m_OSvi.szCSDVersion[i] != ' ') 
  112.                 break;
  113.             m_OSvi.szCSDVersion[i] = '\0';
  114.         }
  115.  
  116.         //    strip leading
  117.         nTemp = i;
  118.         for (i=0; i<nTemp; i++)
  119.         {
  120.             if ((char) m_OSvi.szCSDVersion[i] != ' ') 
  121.                 break;
  122.         }
  123.         strcpy(m_szCSDVersion, &m_OSvi.szCSDVersion[i]);
  124.     }
  125.     else
  126.         m_szCSDVersion[0] = '\0';                // No CSD info, make it blank to avoid errors
  127.  
  128.  
  129.     // Set all options to false by default
  130.     m_bWinNT    = false;
  131.     m_bWin9x    = false;
  132.  
  133.     m_bWinNT4    = false;    m_bWinNT4orLater    = false;
  134.     m_bWin2000    = false;    m_bWin2000orLater    = false;
  135.     m_bWinXP    = false;    m_bWinXPorLater        = false;
  136.     m_bWin2003  = false;    m_bWinVista            = false;
  137.  
  138.     m_bWin98    = false;    m_bWin98orLater        = false;
  139.     m_bWin95    = false;    m_bWin95orLater        = false;
  140.     m_bWinMe    = false;    m_bWinMeorLater        = false;
  141.  
  142.  
  143.     // Work out if NT or 9x
  144.     if (m_OSvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
  145.     {
  146.         // Windows NT
  147.         m_bWinNT = true;
  148.  
  149.         switch (m_dwMajorVersion)
  150.         {
  151.             case 4:                                // NT 4
  152.                 m_bWinNT4 = true;
  153.                 m_bWinNT4orLater = true;
  154.                 break;
  155.  
  156.             case 5:                                // Win2000 / XP
  157.                 m_bWinNT4orLater = true;
  158.                 m_bWin2000orLater = true;
  159.                 if ( m_dwMinorVersion == 0 )    // Win2000
  160.                     m_bWin2000 = true;
  161.                 else // minor is 1 (XP), 2 (2003), or beyond.
  162.                 {
  163.                     m_bWinXPorLater = true;
  164.                     if ( m_dwMinorVersion == 1 )
  165.                         m_bWinXP = true;
  166.                     else if ( m_dwMinorVersion == 2 )
  167.                         m_bWin2003 = true;
  168.                     //else it's something later than XP/2003, so there is nothing more to be done.
  169.                 }
  170.                 break;
  171.  
  172.             case 6:                                // Windows Vista
  173.                 m_bWinNT4orLater = true;
  174.                 m_bWin2000orLater = true;
  175.                 m_bWinXPorLater = true;
  176.                 m_bWinVista = true;
  177.                 break;
  178.  
  179.         } // End Switch
  180.     }
  181.     else
  182.     {
  183.         // Windows 9x -- all major versions = 4
  184.         m_bWin9x = true;
  185.         m_bWin95orLater = true;
  186.         m_dwBuildNumber    = (WORD) m_OSvi.dwBuildNumber;    // Build number in lower word on 9x
  187.  
  188.         switch ( m_dwMinorVersion )
  189.         {
  190.             case 0:                                // 95
  191.                 m_bWin95 = true;
  192.                 break;
  193.  
  194.             case 10:                            // 98
  195.                 m_bWin98 = m_bWin98orLater = true;
  196.                 break;
  197.  
  198.             case 90:                            // ME
  199.                 m_bWinMe =     m_bWinMeorLater = m_bWin98orLater = true;
  200.                 break;
  201.         } // End Switch
  202.     } // End If
  203.  
  204. } // Init()
  205.  
  206.